
package com.zhu.salesmanagement.network;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.dms2.salesmanagement.R;
import com.zhu.salesmanagement.VisitTaskListActivity;
import com.zhu.salesmanagement.common.Actions;
import com.zhu.salesmanagement.models.CEvaluationItem;
import com.zhu.salesmanagement.models.CustomerShelfsItem;
import com.zhu.salesmanagement.models.ProductInfo;
import com.zhu.salesmanagement.provider.SalesSettings;
import com.zhu.salesmanagement.utils.Util;
import com.zhu.salesmanagement.views.ComprehensiveEvaluationView;
import com.zhu.salesmanagement.views.ProductInfoListView;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

/**
 * 拜访 货架 考核结果等数据获取
 */

public class CustomerShelfData {

    private Context mContext = null;
    private String sEmployeeID = null;
    private String mUuid = null;
    private String[] mFloorType = null;
    private String[] mProductInfoType = null;
    private String[] mResultType = null;
    private List<Object> mVisitedList = new ArrayList<Object>(); //门店拜访结果
    private List<Object> mShelfList = new ArrayList<Object>(); //货架信息结果
    private List<Object> mCRCList = new ArrayList<Object>(); //CRC考核结果
    private List<Object> mCheckResultList = new ArrayList<Object>(); //大区考核结果
    private List<Object> mCheckImportMsgList = new ArrayList<Object>(); //考核重要讯息
    private String mWhere = "";
    private String mCustomerID = null;

    /**
     * 构造函数
     * @param context 上下文
     * @param eid 业务员ID
     * @param uuid 授权ID
     */
    public CustomerShelfData(Context context, String eid, String uuid) {
        mContext = context;
        sEmployeeID = eid;
        mUuid = uuid;
    }

    /**
     * 构造函数
     * @param context 上下文
     * @param eid 业务员ID
     * @param uuid 授权ID
     * @param cid 门店ID
     */
    public CustomerShelfData(Context context, String eid, String uuid, String cid) {
        mContext = context;
        sEmployeeID = eid;
        mUuid = uuid;
        mCustomerID = cid;
    }

    /**
     * 获取处理数据
     */
    public void parseData() {
    	mWhere = "";
    	clear();
    	parseVisiedData();
    	parseCustomer();
    }

    /**
     * 处理CRC考核数据
     */
    private void parseCustomer(){
    	 Cursor cursor = null;
         try {
        	 if(mWhere == null || mWhere.length() < 2){
        		 mWhere = SalesSettings.StoreCheckInfoColumns.DATATYPE +" = 1";
        		 Log.e("zhu", "no Customer data ="+mWhere);
        		 return;
        	 }
             cursor = mContext.getContentResolver().query(
                     SalesSettings.StoreCheckInfoColumns.CONTENT_URI, null, mWhere, null, null);
             final int storeIdIndex = cursor
                     .getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.STOREID);
             final int goodsTypeIndex = cursor
                     .getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.TYPEID);
             final int placeIndex = cursor
                     .getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.PLACE);
             final int floorIndex = cursor
                     .getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.FLOOR);
             final int typeIndex = cursor
             .getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.TYPE);
             final int sideIndex = cursor.getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.SIDE);
             final int goodsIndex = cursor
                     .getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.GOODS);
             final int dtaidIndex = cursor.getColumnIndexOrThrow(SalesSettings.StoreCheckInfoColumns.DTASKACTUALID);

             while (cursor.moveToNext()) {
                 String cid = cursor.getString(storeIdIndex);
                 String dtaid = cursor.getString(dtaidIndex);
                 if(Actions.DEBUG){
                     Log.e("zhu", "cid=" + cid +"  dtaid="+dtaid);
                 }
                 List<Object> cplist = getCustomerCPlist(getShelfCustomerMap(cid, mShelfList));
                 Map<String, Object> map = new HashMap<String, Object>();
                 String cpid = cursor.getString(goodsTypeIndex);
                 int place = cursor.getInt(placeIndex);
                 if(place == ProductInfoListView.INVALID_VALUE){
                	 place = 0;
                 }
                 int side = cursor.getInt(sideIndex);
                 if(side == ProductInfoListView.INVALID_VALUE){
                	 side = 0;
                 }
                 int floor = cursor.getInt(floorIndex);
                 if(floor == ProductInfoListView.INVALID_VALUE){
                     floor = 0;
                 }
                 int type = cursor.getInt(typeIndex);
                 if(type == ProductInfoListView.INVALID_VALUE){
                     type = 0;
                 }

                 map.put("sProductCategoryID", cpid);
                 map.put("iShelfCount", place);
                 map.put("iShelfLayer", floor/*getFloorText(floor)*/);
                 map.put("iShelfArea", side);
                 map.put("sShelfType", getTypeText(type));

                 cplist.add(map);
                 if(Actions.DEBUG){
                     Log.e("zhu", "cpsize=" + cplist.size() +" cpid="+cpid);
                 }
                 addCRCList("", cid, cpid, cursor.getString(goodsIndex), dtaid);
             }
         } catch (Exception e) {
             if (Actions.DEBUG) {
                 e.printStackTrace();
             }
         } finally {
             if (cursor != null) {
                 cursor.close();
                 cursor = null;
             }
         }
    }

    /**
     * 处理门店拜访数据
     */
    private void parseVisiedData(){
    	Cursor cursor = null;
   	 	try{
   	 	    String where = null;
   	 	    if(mCustomerID != null){
   	 	        where = SalesSettings.VisitedStoresColumns.STOREID + " = \'" + mCustomerID + "\'";
   	 	    }
            cursor = mContext.getContentResolver().query(SalesSettings.VisitedStoresColumns.CONTENT_URI, null, where, null, null);
            final int storeidIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.STOREID);
            final int checkintimeIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.CHECKIN_TIME);
            final int taskidIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.TASKID);
            final int taskdateIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.TASTDATE);
            final int aeidIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.AEMPLOYEEID);
            final int checkinLatIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.CHECKIN_LAT);
            final int checkinLngIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.CHECKIN_LNG);
            final int dtaidIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.DTASKACTUALID);
            final int checkresultIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.CHECKRESULT);
            final int checkinfoIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.CHECKRINFO);
            final int vcidIndex = cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.VISITCATEGOR);

            String[] tid = getDatingTaskID();
            if(Actions.DEBUG){
                Log.e("zhu", "tid="+tid);
            }
            while (cursor.moveToNext()) {
                String checkintime = cursor.getString(checkintimeIndex);
                if(Actions.DEBUG){
                	Log.e("zhu","checkintime="+checkintime);
                }
                if(checkintime != null && checkintime.length() > 1){
                	Map map = new HashMap<String, Object>();
                	String dtaid = cursor.getString(dtaidIndex);
                    map.put("sDatingTaskActualID", dtaid);
                    String taskdata = cursor.getString(taskdateIndex);
                    if(taskdata == null || taskdata.trim().length() == 0){
                        taskdata = tid[1];
                    }
                    if(taskdata == null){
                        taskdata = "0";
                    }
                    map.put("dActualDate", new Date(Long.parseLong(taskdata)));

                    map.put("dSignInTime", new Date(Long.parseLong(checkintime)));
                    String lng = cursor.getString(checkinLngIndex);
                    if(lng == null || lng.trim().length() < 1){
                    	lng = "0";
                    }
                    map.put("decSignInLongitude", Double.parseDouble(lng));
                    String lat = cursor.getString(checkinLatIndex);
                    if(lat == null || lat.trim().length() < 1){
                    	lat = "0";
                    }
                    map.put("decSignInLatitude", Double.parseDouble(lat));

                    String aeid = cursor.getString(aeidIndex);
                    if(aeid == null){
                    	aeid = Util.mVerifyUserResult.id;
                    }
                    String cid = cursor.getString(storeidIndex);
                    map.put("sVisitEmployeeID", aeid);
                    map.put("iVisitCategory", cursor.getInt(vcidIndex));
                    map.put("sCustomerID", cid);

                    String dtid = cursor.getString(taskidIndex);
                    if((dtid == null || dtid.trim().length() == 0) && (cid.equals(VisitTaskListActivity.STARTCHECKID) || cid.equals(VisitTaskListActivity.STOPCHECKID))){
                        dtid = tid[0];
                    }
                    if(dtid == null){
                        dtid = "";
                    }
                    if(Actions.DEBUG){
                    	Log.e("zhu","dtid="+dtid + "," +dtaid +",cid="+cid);
                    }
                    map.put("sDatingTaskID", dtid);
                    String checkResult = cursor.getString(checkresultIndex);
                    if(checkPutData(checkResult, cid)){
                    	if(mWhere.length() == 0){
                        	mWhere = SalesSettings.StoreCheckInfoColumns.STOREID + " = \'" + cursor.getString(storeidIndex) + "\'" 
                        			+ " AND " + SalesSettings.StoreCheckInfoColumns.DATATYPE +" = 1";
                        }else{
                        	mWhere += " OR " + SalesSettings.StoreCheckInfoColumns.STOREID + " = \'" + cursor.getString(storeidIndex) + "\'" 
                        			+ " AND " + SalesSettings.StoreCheckInfoColumns.DATATYPE +" = 1";
                        }
                    	mVisitedList.add(map);
                        parseCheckResult(checkResult, dtaid);
                        parseCheckImportMsg(cursor.getString(checkinfoIndex) ,dtaid, cid);
                    }else{
                    	Log.e("zhu","no visit data = " + cid);
                    }
                }
            }
        }catch(Exception e){
        	e.printStackTrace();
            if(Actions.DEBUG){
            	Log.e("zhu","getVistedTaskList error");
            }
        }finally{
            if(cursor != null){
                cursor.close();
                cursor = null;
            }
        }
    }

    /**
     * 组装获取信息上传格式数据
     * @param customerId 门店ID
     * @param list 单个大类货架信息
     */
    private Map<String, Object> getShelfCustomerMap(String customerId, List<Object> list) {
        Map<String, Object> map = null;
        for (int i = 0; i < list.size(); i++) {
            map = (Map<String, Object>) list.get(i);
            Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, Object> entry = iter.next();
                String key = entry.getKey();
                Object value = entry.getValue();
                if (key.equals("sCustomerID")) {
                    if (((String) value).equals(customerId)) {
                        return map;
                    }
                }
            }
        }
        map = new HashMap<String, Object>();
        map.put("sCustomerID", customerId);
        list.add(map);
        return map;
    }

    /**
     * 组装重要信息等信息上传格式数据
     * @param customerId 门店ID
     * @param list 单个大类重要和竞品信息
     * @param dtaid sDatingTaskActualID
     */
    private Map<String, Object> getOtherCustomerMap(String customerId, List<Object> list, String dtaid) {
        Map<String, Object> map = null;
        for (int i = 0; i < list.size(); i++) {
            map = (Map<String, Object>) list.get(i);
            Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, Object> entry = iter.next();
                String key = entry.getKey();
                Object value = entry.getValue();
                if (key.equals("sCustomerID")) {
                    if (((String) value).equals(customerId)) {
                        return map;
                    }
                }
            }
        }
        map = new HashMap<String, Object>();
        map.put("sDatingTaskActualID", dtaid/*Util.getDatingTaskActualID(Util.mVerifyUserResult.id, customerId)*/);
        map.put("sCustomerID", customerId);
        list.add(map);
        return map;
    }

    private List<Object> getCustomerCPlist(Map<String, Object> map) {
        List<Object> listcp = (List<Object>) map.get("CustomerShelf");
        if (listcp == null) {
            listcp = new ArrayList<Object>();
            map.put("CustomerShelf", listcp);
        }
        return listcp;
    }

    private List<Object> getCustomerOtherlist(Map<String, Object> map) {
        List<Object> listcp = (List<Object>) map.get("DatingTaskActualOther");
        if (listcp == null) {
            listcp = new ArrayList<Object>();
            map.put("DatingTaskActualOther", listcp);
        }
        return listcp;
    }

    /**
     * 添加CRC考核数据
     * @param taskid 
     * @param cid sCustomerID
     * @param pcid sProductCategoryID
     * @param goods 产品考评结果
     * @param dtaid sDatingTaskActualID
     */
    private void addCRCList(String taskid, String cid, String pcid, String goods, String dtaid){
    	if(goods == null || goods.trim().length() == 0){
    		if (Actions.DEBUG) {
                Log.e("zhu", "not have product=" + pcid);
            }
    		return;
    	}
    	String[] rowGoods = goods.split(ProductInfoListView.SPLIT_ROW);
        for (int i = 0; i < rowGoods.length; i++) {
            if (Actions.DEBUG) {
                Log.e("zhu", "xx=" + rowGoods[i]);
            }
            String[] rankGoods = rowGoods[i].split(ProductInfoListView.SPLIT_RANK);
            if(rankGoods.length == 5){
            	if (Actions.DEBUG) {
                    Log.e("zhu", "----is CRC info");
                }
                return;
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("sDatingTaskActualID", dtaid);
            map.put("sCustomerID", cid);
            map.put("sProductCategoryID", pcid);
            map.put("sProductID", rankGoods[0]);
            if(rankGoods.length > 2){
            	if (rankGoods[1].equals(ProductInfoListView.DEFAULT)) {
                    rankGoods[1] = "-1";
                }
            	map.put("iLayer", Integer.parseInt(rankGoods[1]));
            	if (rankGoods[2].equals(ProductInfoListView.DEFAULT)) {
                    rankGoods[2] = "-1";
                }
            	map.put("iFacing", Integer.parseInt(rankGoods[2]));
            	if (rankGoods[3].equals(ProductInfoListView.DEFAULT)) {
            		rankGoods[3] = "-1";
            	}
            	map.put("sResult", rankGoods[3]);
            	if (rankGoods[4].equals(ProductInfoListView.DEFAULT)) {
            		rankGoods[4] = "-1";
            	}
            	map.put("sSecondExhibitionID", rankGoods[4]);

            	if (rankGoods[5].equals(ProductInfoListView.DEFAULT)) {
                    rankGoods[5] = "-1";
                }
            	map.put("decStorePrice", Double.parseDouble(rankGoods[5]));
            	map.put("decStockQty", Double.parseDouble("0"));
            	
            }else{
            	if (rankGoods[1].equals(ProductInfoListView.DEFAULT)) {
                    rankGoods[1] = "-1";
                }
            	map.put("iLayer", -1);
            	map.put("iFacing", -1);
            	map.put("decStockQty", Double.parseDouble(rankGoods[1]));
            	map.put("decStorePrice",  -1);
            	map.put("sSpecialExhibitionID", "");
            }
            mCRCList.add(map);
        }
    }

    public List<Object> getShelfList(){
    	if(mShelfList.size() > 0){
    		return mShelfList;
    	}
    	return null;
    }

    public List<Object> getCRCList(){
    	if(mCRCList.size() > 0){
    		return mCRCList;
    	}
    	return null;
    }

    public Object[] getShelfObject(){
    	if(Actions.DEBUG){
    		Log.e("zhu","getShelfObject="+mShelfList.size());
    	}
    	if(mShelfList.size() > 0){
    		return new Object[]{sEmployeeID, mUuid, mShelfList};
    	}else{
    		return null;
    	}
    }

    public Object[] getCRCObject(){
    	if(Actions.DEBUG){
    		Log.e("zhu","getCRCObject="+mCRCList.size());
    	}
    	if(mCRCList.size() > 0){
    		return new Object[]{sEmployeeID, mUuid, mCRCList};
    	}else{
    		return null;
    	}
    }

    public Object[] getCheckResultObject(){
        if(Actions.DEBUG){
            Log.e("zhu","getCheckResultObject="+mCheckResultList.size());
        }
        if(mCheckResultList.size() > 0){
            return new Object[]{sEmployeeID, mUuid, mCheckResultList};
        }else{
            return null;
        }
    }

    public Object[] getCheckImportMsgObject(){
        if(Actions.DEBUG){
            Log.e("zhu","getCheckImportMsgObject="+mCheckImportMsgList.size());
        }
        if(mCheckImportMsgList.size() > 0){
            return new Object[]{sEmployeeID, mUuid, mCheckImportMsgList};
        }else{
            return null;
        }
    }

    public Object[] getVisitedTaskObject(){
    	if(Actions.DEBUG){
    		Log.e("zhu","getVisitedTaskObject="+mVisitedList.size());
    	}
    	if(mVisitedList.size() > 0){
    		return new Object[]{sEmployeeID, mUuid, mVisitedList};
    	}else{
    		return null;
    	}
    }

    private void clear(){
    	if(mShelfList != null){
    		mShelfList.clear();
    	}
    	if(mCRCList != null){
    		mCRCList.clear();
    	}
    	if(mVisitedList != null){
    		mVisitedList.clear();
    	}
    	if(mCheckResultList != null){
    	    mCheckResultList.clear();
    	}
    	if(mCheckImportMsgList != null){
    	    mCheckImportMsgList.clear();
    	}
    }

    public void destory(){
    	if(mShelfList != null){
    		mShelfList.clear();
    		mShelfList = null;
    	}
    	if(mCRCList != null){
    		mCRCList.clear();
    		mCRCList = null;
    	}
    	if(mVisitedList != null){
    		mVisitedList.clear();
    		mVisitedList = null;
    	}
    	if(mCheckResultList != null){
            mCheckResultList.clear();
            mCheckResultList = null;
        }
    	if(mCheckImportMsgList != null){
            mCheckImportMsgList.clear();
            mCheckImportMsgList = null;
        }
    }

    /**
     * 清除保存的数据
     */
    public void delteSqData(){
        if(Util.isEndVisit(mContext)){
            if(Actions.DEBUG){
                Log.e("zhu","delete All data");
            }
            mContext.getContentResolver().delete(SalesSettings.VisitedStoresColumns.CONTENT_URI, null, null);
            mContext.getContentResolver().delete(SalesSettings.StoreCheckInfoColumns.CONTENT_URI, null/*SalesSettings.StoreCheckInfoColumns.DATATYPE +" = 1"*/, null);
        }
    }

    /**
     * 获取DatingTaskID
     */
    private String[] getDatingTaskID(){
        String[] id = new String[2];
        Cursor cursor = null;
        try{
            cursor = mContext.getContentResolver().query(SalesSettings.VisitedStoresColumns.CONTENT_URI, new String[]{ SalesSettings.VisitedStoresColumns.TASKID , SalesSettings.VisitedStoresColumns.TASTDATE}, null, null, null);
            while (cursor.moveToNext()) {
                String tid = cursor.getString(cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.TASKID));
                if(tid != null && tid.trim().length() > 0){
                    id[0] = tid;
                }
                String data = cursor.getString(cursor.getColumnIndexOrThrow(SalesSettings.VisitedStoresColumns.TASTDATE));
                if(data != null && data.trim().length() > 0){
                    id[1] = data;
                    break;
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            id[0] = null;
            id[1] = null;
        }finally{
            if(cursor != null){
                cursor.close();
                cursor = null;
            }
        }
        return id;
    }

    private String getFloorText(int selectIndex){
    	if(mFloorType == null){
    		mFloorType = mContext.getResources().getStringArray(R.array.floor_type);
    	}
    	if(selectIndex >= 0 && selectIndex < mFloorType.length){
    		return mFloorType[selectIndex];
    	}
    	return "";
    }

    /**
     * 获取货架位置
     */
    private String getTypeText(int selectIndex){
        if(mProductInfoType == null){
            mProductInfoType = mContext.getResources().getStringArray(R.array.productinfo_type);
        }
        if(selectIndex >= 0 && selectIndex < mProductInfoType.length){
            return mProductInfoType[selectIndex];
        }
        return "";
    }

    private String getCheckResultType(int selectIndex){
        if(mResultType == null){
            mResultType = mContext.getResources().getStringArray(R.array.compare_type);
        }
        if(selectIndex >= 0 && selectIndex < mResultType.length){
            return mResultType[selectIndex];
        }
        return "";
    }

    /**
     * 解析大区考核结果数据
     * @param result 考核结果
     * @param dtaid sDatingTaskActualID
     */
    private void parseCheckResult(String result, String dtaid){
        if (result != null && result.trim().length() > 0) {
            String[] rowGoods = result.split(ComprehensiveEvaluationView.SPLIT_ROW);
            for (int i = 0; i < rowGoods.length; i++) {
                if (Actions.DEBUG) {
                    Log.e("zhu", "xx=" + rowGoods[i]);
                }
                String[] rankGoods = rowGoods[i].split(ComprehensiveEvaluationView.SPLIT_RANK);
                Map map = new HashMap<String, Object>();
                map.put("sDatingTaskActualID", dtaid);
                map.put("iItemNo", rankGoods[0]);
                if(rankGoods[1].equals(ProductInfoListView.DEFAULT)){
                    rankGoods[1] = "-1";
                }
                map.put("sResult", rankGoods[1]);
                mCheckResultList.add(map);
            }
        }
    }

    /**
     * 保存重要讯息数据
     * @param result 重要讯息
     * @param dtaid sDatingTaskActualID
     * @param cid 门店ID
     */
    private void parseCheckImportMsg(String result, String dtaid, String cid){
        if(result != null && result.trim().length() > 0){
            Map map = new HashMap<String, Object>();
            map.put("sDatingTaskActualID", dtaid);
            map.put("sCustomerID", cid);
            map.put("sImportantMSG", result);
            mCheckImportMsgList.add(map);
        }
    }

    /**
     * 更新重要讯息
     */
    public void updateSCImsg(){
    	if(mCheckImportMsgList != null){
    		for(int i = 0; i < mCheckImportMsgList.size(); i++){
    			Map map = (Map)mCheckImportMsgList.get(i);
    			String cid = (String)map.get("sCustomerID");
    			String msg = (String)map.get("sImportantMSG");
    			updateMsgDb(cid, msg);
    		}
    	}
    }

    private void updateMsgDb(String cid, String msg){
    	String where = SalesSettings.PusherInfoColumns.STOREID + " = \'" + cid +" \'";
        long id = -1;
        Cursor cursor = mContext.getContentResolver().query(SalesSettings.CustomerSColumns.CONTENT_URI, new String[] { SalesSettings.CustomerSColumns._ID }, where, null, null);
        if(cursor != null && cursor.moveToFirst()){
        	id =cursor.getLong(cursor.getColumnIndexOrThrow(SalesSettings.CustomerSColumns._ID));
        }
        if(cursor != null){
            cursor.close();
            cursor = null;
        }
        ContentValues values = new ContentValues();
        values.put(SalesSettings.CustomerSColumns.IMPORTANTINFO, msg);
        if(id != 1){
        	mContext.getContentResolver().update(SalesSettings.CustomerSColumns.getContentUri(id, false), values, null, null);
        }
    }

    /**
     * 检测是否可以上传数据
     * @param result 考核结果
     * @param customerID 门店ID
     */
    private boolean checkPutData(String result, String customerID){
		if (result != null && result.trim().length() > 0) {
			return true;
		}
		Cursor cursor = null;
		try {
			String where = SalesSettings.StoreCheckInfoColumns.STOREID + "=\'"
					+ customerID + "\'";
			cursor = mContext.getContentResolver().query(
					SalesSettings.StoreCheckInfoColumns.CONTENT_URI,
					SyncUtils.PROJECTION, where, null, null);
			if (cursor != null && cursor.getCount() > 0) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			Log.e("zhu", "checkPutData error");
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;
			}
		}
		return false;
    }
}
